/**
 * @file lsm303d.h
 * @author CuiQQ (you@domain.com)
 * @brief 本文件为lsm303d磁力计模块提供实现需求，由lsm303d.c来实现具体操作
 * @version 0.1
 * @date 2022-12-19
 * 
 * @copyright Copyright (c) 2022
 * 
 */

#include "stdint.h"
#include "string.h"
//Register Address Map
#define LSM_TEMP_OUT_L		0x05U
#define LSM_TEMP_OUT_H		0x06U
#define LSM_STATUS_M		0x07U
#define LSM_OUT_X_L_M		0x08U
#define LSM_OUT_X_H_M		0x09U
#define LSM_OUT_Y_L_M		0x0AU
#define LSM_OUT_Y_H_M		0x0BU
#define LSM_OUT_Z_L_M		0x0CU
#define LSM_OUT_Z_H_M		0x0DU
#define LSM_WHO_AM_I		0x0FU	//0x49
#define LSM_INT_CTRL_M		0x12U	//0xE8  磁力计中断配置，不启用0x00，感觉默认值应该是0x00
#define LSM_INT_SRC_M		0x13U	//阈值触发配置
#define LSM_INT_THS_L_M		0x14U	//阈值配置
#define LSM_INT_THS_H_M		0x15U
#define LSM_OFFSET_X_L_M	0x16U	//漂移量设置
#define LSM_OFFSET_X_H_M	0x17U
#define LSM_OFFSET_Y_L_M	0x18U
#define LSM_OFFSET_Y_H_M	0x19U
#define LSM_OFFSET_Z_L_M	0x1AU
#define LSM_OFFSET_Z_H_M	0x1BU
#define LSM_REFERENCE_X		0x1CU	//与加速度数据进行高通滤波的参考值
#define LSM_REFERENCE_Y		0x1DU
#define LSM_REFERENCE_Z		0x1EU
#define LSM_CTRL0			0x1FU	//0x00  高通滤波器启用与FIFO启用 0x00
#define LSM_CTRL1			0x20U	//0x07  加速度计频率 加速度各轴使能与更新方式 0x37启用所有，频率为12.5Hz
#define LSM_CTRL2			0x21U	//0x00  加速度计带宽与范围以及自检 0xC8不自检 0xCA自检   50Hz带宽，+-4g量程
#define LSM_CTRL3			0x22U	//0x00  中断配置 0x00
#define LSM_CTRL4			0x23U	//0x00  中断配置 0x00
#define LSM_CTRL5			0x24U	//0x18  温度检测使能 磁力计精度与频率，0xE8 启用温度检测，频率为12.5Hz
#define LSM_CTRL6			0x25U	//0x20  磁力计范围 0x20默认4gauss
#define LSM_CTRL7			0x26U	//0x01  特殊模式 磁力计连续转换 0x80
#define LSM_STATUS_A		0x27U
#define LSM_OUT_X_L_A		0x28U
#define LSM_OUT_X_H_A		0x29U
#define LSM_OUT_Y_L_A		0x2AU
#define LSM_OUT_Y_H_A		0x2BU
#define LSM_OUT_Z_L_A		0x2CU
#define LSM_OUT_Z_H_A		0x2DU
#define LSM_FIFO_CTRL		0x2EU	//FIFO配置
#define LSM_FIFO_SRC		0x2FU	//FIFO状态
#define LSM_IG_CFG1			0x30U	//IG均为中断相关
#define LSM_IG_SRC1			0x31U
#define LSM_IG_THS1			0x32U
#define LSM_IG_DUR1			0x33U
#define LSM_IG_CFG2			0x34U
#define LSM_IG_SRC2			0x35U
#define LSM_IG_THS2			0x36U
#define LSM_IG_DUR2			0x37U
#define LSM_CLICK_CFG		0x38U	//中断相关
#define LSM_CLICK_SRC		0x39U
#define LSM_CLICK_THS		0x3AU
#define LSM_TIME_LIMIT		0x3BU
#define LSM_TIME_LATENCY	0x3CU
#define LSM_TIME_WINDOW		0x3DU
#define LSM_Act_THS			0x3EU
#define LSM_Act_DUR			0x3FU

#define LSM303D_ADDR		0x3C

#define LSM_ACC_FCT			0.00119708f		//单位换算为：m/s^2，重力是9.8065
#define LSM_MAG_FCT			0.08f			//单位换算为：mgauss，磁场是500~600mguass

#define LSM303D_WHO_AM_I_ID  0x49
#define LSM303D_MAX_RDWR_LEN 32


typedef struct __3AxisMagDataStruct
{
    uint16_t MagData_X;
    uint16_t MagData_Y;
    uint16_t MagData_Z;
}_3AxisMagDataStruct;

/**
 * @brief 获取三轴磁力计数据
 * 
 */
int8_t LSM303D_PollingMagRawData(_3AxisMagDataStruct *raw_data);

/**
 * @brief 获取温度数据
 * 
 */
int8_t LSM303D_PollingTempRawData(uint16_t *temp_data);


/**
 * @brief 获取who am I ID
 * 
 */
int8_t LSM303D_GetWhoAmI(uint8_t *who_am_i);

int8_t LSM303D_SetRegMode(void);
